<template>
<h2>用户登录页面</h2>
<table class="table-bordered" border="1">
    <tr>
        <td>用户名</td>
        <td>
            <input type="text" v-model="Info.UserName" placeholder="请输入用户名" />
        </td>
    </tr>
    <tr>
        <td>密码</td>
        <td>
            <input type="password" v-model="Info.UserPwd" placeholder="请输入密码" />
        </td>
    </tr>
    <tr>
        <td colspan="2">
        <input type="button" value="登录" class="btn btn-primary"  @click="LoginDen" />
        </td>
    </tr>
</table>


</template>


<script setup lang="ts">
import axios from 'axios';
import { ref } from 'vue';  
import { useRouter } from 'vue-router';


const router = useRouter();

const Info = ref({
        UserName: '',
        UserPwd: '',
});
const LoginDen = () => {
   axios.get("http://localhost:61413/api/User/LoginPassword",{
    params:{
        UserName: Info.value.UserName,
        UserPwd: Info.value.UserPwd,
    }
   })
   .then((res) => {
    if(res.data == -1){
        alert("用户不存在，请添加")
        router.push("/LoginShow")
    }else if(res.data==null){
        alert("用户名或密码不匹配，请检查！");
    }else{
        ChanType(res.data.UserId);
        console.log(res.data.UserId)
    }
   })
}
//判断用户类型
const ChanType=(UserId:number)=>{
    axios.get("http://localhost:61413/api/User/ChangType",{
        params:{
            UserId:UserId
        }
    }).then(res=>{
        if(res.data.UType =="管理员"){
            alert("管理员登录成功！")
            
            router.push("/LoginShow")
        }else{
            alert("用户登录成功！")
            router.push('/BoorowShow')
        }
    })
}

</script>